<%@page import="com.asd.util.PageBean"%>
<%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
<%@page import="com.asd.vo.User"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
<script src="/OnlineExam/js/jquery.min.js"></script>
<script src="/OnlineExam/layui/lay/modules/layer.js"></script>
<link rel="stylesheet" href="/OnlineExam/layui/css/modules/layer/default/layer.css">
</head>
<body>
<% List<User>list =(List)request.getAttribute("apage"); 
   PageBean pb = (PageBean)request.getAttribute("pb");
%>
<h1>学生管理</h1>
    <button class="btnadd">创建学生</button><a href="student-upload.jsp">批量导入</a>
    <hr>
    
    <table border="1" style="width: 80%;">
        <tr>
            <th><input type="checkbox" name="st"></th>
            <th>姓名</th><th>性别</th><th>班级</th><th>电话</th><th>微信</th><th>操作</th>
        </tr>
        <%--
        for(User user:list){
        out.print("<tr>");
        out.print("<td><input type='checkbox' name='st'></td>");
        out.print("<td>"+user.getUser_name()+"</td><td>男</td><td>101班</td><td>1110</td><td>asd</td>");
        out.print("<td><button class='btnlook' dataid="+user.getUser_id()+">查看</button><button class='btnupdate' dataid="+user.getUser_id()+">修改</button><button class='btndel' dataid="+user.getUser_id()+">删除</button></td>");
        out.print("</tr>");
        
        }
        --%>
        <c:forEach items="${apage }" var="stu">
        <tr>
        <td><input type='checkbox' name='st'></td>
        <td>${stu.user_name }</td><td>男</td><td>101班</td><td>1110</td><td>asd</td>
        <td><button class='btnlook' dataid="${stu.user_id }">查看</button><button class='btnupdate' dataid="${stu.user_id }">修改</button><button class='btndel' dataid="${stu.user_id }">删除</button></td>
        </c:forEach>
        
    </table>
 
    <c:forEach begin="${pb.beginNum }" end="${pb.endNum }" var="k">
	<c:if test="${k==pb.curPage }">
    	<a style="color:red" href='stu?m=page&p=${k}'>${k}</a>
    </c:if>
    <c:if test="${k!=pb.curPage }">
    	<a href='stu?m=page&p=${k}'>${k}</a>
    </c:if>
    </c:forEach>

    <script>
        $(".btnadd").click(function(){
            layer.confirm("姓名:<input type='text' class='add_name'><br>性别:<input type='text' class='add_sex'><br>班级:<input type='text' class='add_class'><br>电话:<input type='text' class='add_phone'><br>微信:<input type='text' class='add_wx'>",
            		{btn:['确定','取消'],title:'添加学生'},function(index){
            			var name = $(".add_name").val();
            			var sex = $(".add_sex").val();
            			var classes = $(".add_class").val();
            			var phone = $(".add_phone").val();
            			var wx = $(".add_wx").val();
            			location.href="http://localhost:8080/OnlineExam/admin/stu?m=add&name="+name+"&sex="+sex+"&classes="+classes+"&phone="+phone+"&wx="+wx;
            			layer.close(index);
            		})
        })
        
        $(".btndel").click(function(){
        	var id = $(this).attr("dataid");
        	
        	layer.confirm('确定要删除该用户吗?',{btn:['确定','取消'],title:'提示'},function(index){
        		console.log("del ok"+id);
        		location.href="http://localhost:8080/OnlineExam/admin/stu?m=del&uid="+id;
        		layer.close(index);
        	})
        })
        
        $(".btnlook").click(function(){
        	var id = $(this).attr("dataid");
        	$.get("/OnlineExam/admin/stu?m=find&uid="+id,function(data,status){
        		var mydata=$.parseJSON(data);
        		layer.open({
            		title : "查看信息",
            		content : "用户ID: "+mydata.user_id+"<br>"+
            		"班级ID: "+mydata.class_id+"<br>"+
            		"权限: "+mydata.role_id+"<br>"+
            		"用户名: "+mydata.user_name+"<br>"+
            		"性别: "+mydata.user_sex+"<br>"+
            		"电话: "+mydata.user_phone+"<br>"+
            		"微信: "+mydata.user_wx+"<br>"
            	})
        	})
        })
        
        $(".btnupdate").click(function(){
        	var id = $(this).attr("dataid");
        	console.log(id)
            layer.confirm("姓名:<input type='text' class='add_name'><br>性别:<input type='text' class='add_sex'><br>班级:<input type='text' class='add_class'><br>电话:<input type='text' class='add_phone'><br>微信:<input type='text' class='add_wx'>",
            		{btn:['确定','取消'],title:'修改信息'},function(index){
            			var name = $(".add_name").val();
            			var sex = $(".add_sex").val();
            			var classes = $(".add_class").val();
            			var phone = $(".add_phone").val();
            			var wx = $(".add_wx").val();
            			location.href="http://localhost:8080/OnlineExam/admin/stu?m=update&name="+name+"&sex="+sex+"&classes="+classes+"&phone="+phone+"&wx="+wx+"&uid="+id;
            			layer.close(index);
            		})
        })
    </script>
</body>
</html>